package patternmining.model.construction.java;

import patternmining.model.construction.File;
import patternmining.model.construction.SourceDescription;
import patternmining.model.graph.Graph;
import patternmining.model.graph.java.*;

public class JavaFakeSource extends JavaSource {

    public void buildGraph() {
        // construct the Graph of the program that instantiates the Observe Pattern
        graph = new JavaProgram();
        //add the vertices representing the JAvaEntities
        JavaEntity observer = new JavaReferencedType("default.Observer");
        graph.add(observer);
        JavaEntity concreteObserver = new JavaReferencedType("default.ConcreteObserver");
        graph.add(concreteObserver);
        JavaEntity subject = new JavaReferencedType("defaul.Subject");
        graph.add(subject);
        JavaEntity concreteSubject = new JavaReferencedType("default.ConcreteSubject");
        graph.add(concreteSubject);
        JavaEntity attach = new JavaMethod("default.Subject.attach");
        graph.add(attach);
        JavaEntity detach = new JavaMethod("default.Subject.detach");
        graph.add(detach);
        JavaEntity notify = new JavaMethod("default.Subject.notify");
        graph.add(notify);
        JavaEntity get_state = new JavaMethod("default.ConcreteSubject.get-state");
        graph.add(get_state);
        JavaEntity set_state = new JavaMethod("default.ConcreteSubject.set-state");
        graph.add(set_state);
        JavaEntity update = new JavaMethod("default.Observer.update");
        graph.add(update);
        JavaEntity subject_state = new JavaPrimitiveType("default.ConcreteSubject.subject-state");
        graph.add(subject_state);
        JavaEntity observer_state = new JavaPrimitiveType("default.ConcreteObserver.observer-state");
        graph.add(observer_state);
        //add the edges representing the predicates of the formula
        JavaRelationship defined_InSubjectState = new JavaPrimitiveTypeAtribute(subject_state, concreteSubject);
        graph.add(defined_InSubjectState);
        JavaRelationship defined_InObserverState = new JavaPrimitiveTypeAtribute(observer_state, concreteObserver);
        graph.add(defined_InObserverState);
        JavaRelationship defined_InAttach = new JavaMethodDefinition(attach, subject);
        graph.add(defined_InAttach);
        JavaRelationship defined_InDetach = new JavaMethodDefinition(detach, subject);
        graph.add(defined_InDetach);
        JavaRelationship defined_InNotify = new JavaMethodDefinition(notify, subject);
        graph.add(defined_InNotify);
        JavaRelationship defined_InSetState = new JavaMethodDefinition(set_state, concreteSubject);
        graph.add(defined_InSetState);
        JavaRelationship defined_InGetState = new JavaMethodDefinition(get_state, concreteSubject);
        graph.add(defined_InGetState);
        JavaRelationship defined_InUpdate = new JavaMethodDefinition(update, observer);
        graph.add(defined_InUpdate);
        JavaRelationship referenceToOne = new JavaAssociation_to_One(concreteObserver, concreteSubject);
        graph.add(referenceToOne);
        JavaRelationship referenceToMany = new JavaAssociation_to_Many(subject, observer);
        graph.add(referenceToMany);
        JavaRelationship inheritanceObserver = new JavaInheritance(concreteObserver, observer);
        graph.add(inheritanceObserver);
        JavaRelationship inheritanceSubject = new JavaInheritance(concreteSubject, subject);
        graph.add(inheritanceSubject);
        JavaRelationship invocationSetState = new JavaMethodInvocation(set_state, notify);
        graph.add(invocationSetState);
        JavaRelationship invocationNotify = new JavaMethodInvocation(notify, update);
        graph.add(invocationNotify);
        JavaRelationship invocationUpdate = new JavaMethodInvocation(update, get_state);
        graph.add(invocationUpdate);
        JavaRelationship argumentAttach = new JavaArgument(observer, attach);
        graph.add(argumentAttach);
        JavaRelationship argumentDetach = new JavaArgument(observer, detach);
        graph.add(argumentDetach);
        JavaRelationship argumentUpdate = new JavaArgument(subject, update);
        graph.add(argumentUpdate);
    }

    public void setProgramDependency(ProgramDependency dep) {
        // do nothing, since Dependencies are not used in the construction of the fake graph
    }

    public Graph getGraph() {
        return graph;
    }

    public void includeFile(File file) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
 
